/**
 * Dear programmer:
 * When I wrote this code, only god and I knew how it worked.
 * Now, only god knows it!
 *
 * @author: Pegasus  Date: 2018/11/21 Time: 10:06
 *
 * 个人中心
 */

import React, {Component} from 'react';
import {
    Linking,
    SafeAreaView,
    ScrollView,
    TouchableOpacity,
    View,
    NativeModules,
    TouchableHighlight,
    Text,
    Platform,
    BackHandler,
    ToastAndroid,
} from 'react-native';
import {connect} from 'react-redux';
import OffWorkView from "../../../component/OffWorkView/OffWorkView"
import IconsAndTextCellView from "../../../component/IconsAndTextCellView/IconsAndTextCellView";
import DividingLineViewComponent from "../../../component/DividingLineViewComponent/DividingLineViewComponent";
import HS_TouchableHighlight from "../../../hsstyle/HS_TouchableHighlight";
import {styles} from './DiscoverScreen.Style';
import {FONT_COLOR_TITLE} from "../../../constant/PHColors";
import ImageAndTextCellView from "../../../component/ImageAndTextCellView/ImageAndTextCellView";

class DiscoverScreen extends Component {

    static navigationOptions = ({navigation}) => ({
        headerTitle: ``,
        headerLeft: <View><Text style={{marginLeft:15,fontSize:18,color:FONT_COLOR_TITLE}}>发现</Text></View>,
        headerRight: <OffWorkView navigation={navigation}/>
    });

    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {};
    }

    componentWillMount() {
        if (Platform.OS === 'android'||Platform.OS==='ios') {
            BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
        }
    };

    componentWillUnmount() {
        if (Platform.OS === 'android'||Platform.OS==='ios') {
            BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
        }
    };

    onBackAndroid = () =>{
        if(this.props.navigation.isFocused()){//判断   该页面是否处于聚焦状态
            if (this.lastBackPressed && this.lastBackPressed + 2000 >= Date.now()) {
                BackHandler.exitApp();//直接退出APP
            }else{
                this.lastBackPressed = Date.now();
                ToastAndroid.show('再按一次退出应用', 1000);//提示
                return true;
            }
        }
    };

    render() {
        return (
            <SafeAreaView style={styles.body}>

                <ScrollView style={styles.body}>

                    <HS_TouchableHighlight underlayColor={'#f1f1f1'} onPress={() => {
                        this.props.navigation.navigate('ContactsScreen')
                    }}>
                        <IconsAndTextCellView title={'通讯录'}/>
                    </HS_TouchableHighlight>

                    <DividingLineViewComponent lineHeight={1}/>

                    <HS_TouchableHighlight underlayColor={'#f1f1f1'} onPress={() => {
                        this.props.navigation.navigate('StaffSchedule')
                    }}>
                        <IconsAndTextCellView title={'员工班表'}/>
                    </HS_TouchableHighlight>

                    <DividingLineViewComponent lineHeight={1}/>

                    <HS_TouchableHighlight underlayColor={'#f1f1f1'} onPress={() => {
                        this.props.navigation.navigate('AssignRoom',{callBack:()=>{
                            this.props.navigation.navigate('DiscoverScreen');
                        }})
                    }}>
                        <IconsAndTextCellView title={'分配做房'}/>
                    </HS_TouchableHighlight>

                    <DividingLineViewComponent lineHeight={1}/>

                    <HS_TouchableHighlight underlayColor={'#f1f1f1'} onPress={() => {
                        this.props.navigation.navigate('PersonnelStatusScreen')
                    }}>
                        <IconsAndTextCellView title={'人员状态'}/>
                    </HS_TouchableHighlight>

                    <DividingLineViewComponent lineHeight={1}/>

                    <HS_TouchableHighlight underlayColor={'#f1f1f1'} onPress={() => {
                        this.props.navigation.navigate('roomChangeReport')
                    }}>
                        <IconsAndTextCellView title={'换房报表'}/>
                    </HS_TouchableHighlight>

                    <DividingLineViewComponent lineHeight={1}/>

                </ScrollView>

            </SafeAreaView>
        )
    }
}

const props = state => {
    return {}
};

export default DiscoverScreen = connect(props)(DiscoverScreen);